unit idispatch_interface;

{$WARN SYMBOL_PLATFORM OFF}

interface

uses
  ComObj, ActiveX, VNO_TLB, StdVcl, Variants,sysutils;

type
  TTJsToDelphi = class(TAutoObject, ITJsToDelphi)
  protected
    function Get_lng: OleVariant; safecall;
    function Get_MapClick: OleVariant; safecall;
    function Get_MapDblClick: OleVariant; safecall;
    procedure Set_addr(Value: OleVariant); safecall;    
    function Get_MapRightClick: OleVariant; safecall;
    function Get_MapZoomChange: OleVariant; safecall;
    function Get_MarkerClick: OleVariant; safecall;
    function Get_MarkerDragEnd: OleVariant; safecall;
    function Get_mLat: OleVariant; safecall;
    function Get_zoom: OleVariant; safecall;
    procedure Set_lng(Value: OleVariant); safecall;
    procedure Set_mLat(Value: OleVariant); safecall;
    procedure Set_zoom(Value: OleVariant); safecall;
    function Get_addr: OleVariant; safecall;
    procedure Set_addrstr(Value: OleVariant); safecall;
    function Get_addrstr: OleVariant; safecall;
    function Get_AfterRClick: OleVariant; safecall;
    function Get_MarkerDragStart: OleVariant; safecall;
    function Get_MarkerLat: OleVariant; safecall;
    function Get_MarkerLng: OleVariant; safecall;
    procedure Set_MarkerLat(Value: OleVariant); safecall;
    procedure Set_MarkerLng(Value: OleVariant); safecall;
  end;

implementation

uses ComServ, GoogleMap;

function TTJsToDelphi.Get_lng: OleVariant;
begin
  Result:=map.Lng;
end;

function TTJsToDelphi.Get_MapClick: OleVariant;
begin
  map.MapCklick;
end;

function TTJsToDelphi.Get_MapDblClick: OleVariant;
begin
  map.DblClick;
end;

procedure TTJsToDelphi.Set_addr(Value: OleVariant);
begin
  map.addr:=Value;
end;


procedure TTJsToDelphi.Set_addrstr(Value: OleVariant);
begin
  map.addr:=Value;
end;

function TTJsToDelphi.Get_MapRightClick: OleVariant;
begin
  //map.JsEx(Format('AddressByLatLng(%s,%s)',[map.Lat,map.Lng]));
  map.MapRighCklick;
end;

function TTJsToDelphi.Get_MapZoomChange: OleVariant;
begin
  map.ZoomChange;
end;

function TTJsToDelphi.Get_MarkerClick: OleVariant;
begin
  map.Marker.Click;
end;

function TTJsToDelphi.Get_MarkerDragEnd: OleVariant;
begin
  map.Marker.EndDrag;
end;

function TTJsToDelphi.Get_mLat: OleVariant;
begin
  Result:=map.Lat;
end;

function TTJsToDelphi.Get_zoom: OleVariant;
begin
  Result:=map.MapOptions.zoom;
end;

procedure TTJsToDelphi.Set_lng(Value: OleVariant);
var
  i :integer;
  s: string;
begin
  s:=VarToStr(Value);
  i:=Pos(',',s);
  if i<>0 then s[i]:='.';
  map.Lng:=s;
end;

procedure TTJsToDelphi.Set_mLat(Value: OleVariant);
var
  i :integer;
  s :String;
begin
  s:=VarToStr(Value);
  i:=Pos(',',s);
  if i<>0 then s[i]:='.';
  map.Lat:=s;
end;

procedure TTJsToDelphi.Set_zoom(Value: OleVariant);
begin
  map.MapOptions.zoom:=Value;
end;


function TTJsToDelphi.Get_addr: OleVariant;
begin
  Result:=map.addr;
end;


function TTJsToDelphi.Get_addrstr: OleVariant;
begin
  Result:=map.addr;
end;

function TTJsToDelphi.Get_AfterRClick: OleVariant;
begin
  map.AddressGet;
end;

function TTJsToDelphi.Get_MarkerDragStart: OleVariant;
begin
  map.Marker.StartDrag;
end;

function TTJsToDelphi.Get_MarkerLat: OleVariant;
begin
  Result:=map.Marker.Lat;
end;

function TTJsToDelphi.Get_MarkerLng: OleVariant;
begin
  Result := map.Marker.Lng;
end;

procedure TTJsToDelphi.Set_MarkerLat(Value: OleVariant);
var
  i :integer;
  s :String;
begin
  s:=VarToStr(Value);
  i:=Pos(',',s);
  if i<>0 then s[i]:='.';
  map.Marker.Lat:=s;
end;

procedure TTJsToDelphi.Set_MarkerLng(Value: OleVariant);
var
  i :integer;
  s: string;
begin
  s:=VarToStr(Value);
  i:=Pos(',',s);
  if i<>0 then s[i]:='.';
  map.Marker.Lng:=s;
end;

initialization
  TAutoObjectFactory.Create(ComServer, TTJsToDelphi, Class_TJsToDelphi,
    ciMultiInstance, tmApartment);
end.
